﻿using Unity.Entities;
using Unity.Burst;
using Unity.Collections;

[DisableAutoCreation]
public partial struct DestroySystem : ISystem
{
    public void OnCreate(ref SystemState state)
    {
        state.RequireForUpdate<IsDestroyComp>();
    }

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        foreach(Entity entity in SystemAPI.QueryBuilder().WithAll<IsDestroyComp>().Build().ToEntityArray(Allocator.Temp))
        {
            state.EntityManager.DestroyEntity(entity);
        }
    }
}

public struct IsDestroyComp : IComponentData, IEnableableComponent 
{
}